import java.util.concurrent.Semaphore;

public class Demo4 {
    public static void main(String[] args) throws InterruptedException {
        Semaphore semaphore = new Semaphore(4);
        //当前有4个可用资源
        //有几个资源就可以进行几次P操作
        semaphore.acquire();//申请资源
        System.out.println("P 操作");
        semaphore.acquire();
        System.out.println("P 操作");
        semaphore.acquire();
        System.out.println("P 操作");
        semaphore.acquire();
        System.out.println("P 操作");

        semaphore.release();//释放资源
    }
}
